# coding=utf-8

from openpyxl import Workbook
from openpyxl.chart import PieChart, Reference


wb = Workbook()
ws = wb.active

data = [
    ['Category', 'Value'],
    ['A', 10],
    ['B', 20],
    ['C', 30],
]
for row in data:
    ws.append(row)

chart = PieChart()
labels = Reference(ws, min_col=1, min_row=2, max_row=4)
data = Reference(ws, min_col=2, min_row=1, max_row=4)
chart.add_data(data, titles_from_data=True)
chart.set_categories(labels)
chart = PieChart()
labels = Reference(ws, min_col=1, min_row=2, max_row=4)
data = Reference(ws, min_col=2, min_row=1, max_row=4)
chart.add_data(data, titles_from_data=True)
chart.set_categories(labels)

colors = ['FF0000', '00FF00', '0000FF']  # 指定颜色，可以根据需要自定义
for i, point in enumerate(chart.series[0].points):
    point.graphicalProperties.solidFill = colors[i]

ws.add_chart(chart, "E5")

wb.save("chart.xlsx")